/**
 * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.wowjoy.pda.android_pharmacy.common.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class PreferenceManager {
    private static final String PREFERENCE_NAME = "saveInfo";
    private static SharedPreferences mSharedPreferences;
    private static PreferenceManager mPreferencemManager;
    private static SharedPreferences.Editor editor;
    /**
     * 用户
     */
    private static String SHARED_KEY_CURRENTUSER_USERACCESSTOKEN = "SHARED_KEY_CURRENTUSER_USERACCESSTOKEN";
    private static String SHARED_KEY_L_USERNAME = "SHARED_KEY_L_USERNAME";
    private static String SHARED_KEY_L_USERNUM = "SHARED_KEY_L_USERNUM";
    private static String SHARED_KEY_L_USERID = "SHARED_KEY_L_USERID";
    /**
     *  门诊
     */
    private static String SHARED_KEY_L_DOOR_TAKE_PROGRESS_TOTAL = "SHARED_KEY_L_PROGRESS_TOTAL_DOOR_TAKE";
    private static String SHARED_KEY_L_DOOR_PUT_PROGRESS_TOTAL = "SHARED_KEY_L_PROGRESS_TOTAL_DOOR_PUT";

    /**
     * 住院
     */
    private static String SHARED_KEY_L_HOSPITAL_CHECK_PROGRESS_TOTAL = "SHARED_KEY_L_PROGRESS_TOTAL_HOSPITAL_CHECK";
    private static String SHARED_KEY_L_HOSPITAL_TAKE_PROGRESS_TOTAL = "SHARED_KEY_L_PROGRESS_TOTAL_HOSPITAL_TAKE";
    private static String SHARED_KEY_L_HOSPITAL_PUT_PROGRESS_TOTAL = "SHARED_KEY_L_PROGRESS_TOTAL_HOSPITAL_PUT";
    private static String SHARED_KEY_L_HOSPITAL_PILL_PROGRESS_TOTAL = "SHARED_KEY_L_PROGRESS_TOTAL_HOSPITAL_PILL";


    /**
     * 静配
     */
    private static String SHARED_KEY_L_STATIC_CHECK_PROGRESS_TOTAL = "SHARED_KEY_L_PROGRESS_TOTAL_STATIC_CHECK";
    private static String SHARED_KEY_L_STATIC_TAKE_PROGRESS_TOTAL = "SHARED_KEY_L_PROGRESS_TOTAL_STATIC_TAKE";
    private static String SHARED_KEY_L_STATIC_PUT_PROGRESS_TOTAL = "SHARED_KEY_L_PROGRESS_TOTAL_STATIC_PUT";

    private PreferenceManager(Context cxt) {
        mSharedPreferences = cxt.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        editor = mSharedPreferences.edit();
    }

    public static synchronized void init(Context cxt) {
        if (mPreferencemManager == null) {
            mPreferencemManager = new PreferenceManager(cxt);
        }
    }

    public synchronized static PreferenceManager getInstance() {
        if (mPreferencemManager == null) {
            throw new RuntimeException("please init first!");
        }

        return mPreferencemManager;
    }


    public void clearAllCacheMessgae() {
        editor.clear();
        editor.commit();
    }


    public void setCurrentUserAccessToken(String accessToken) {
        editor.putString(SHARED_KEY_CURRENTUSER_USERACCESSTOKEN, accessToken);
        editor.commit();
    }

    public String getCurrentUserAccessToken() {
        return mSharedPreferences.getString(SHARED_KEY_CURRENTUSER_USERACCESSTOKEN, null);
    }

   //存取员工姓名
    public void setLUserName(String name) {
        editor.putString(SHARED_KEY_L_USERNAME, name);
        editor.commit();
    }

    public String getLUserName() {
        return mSharedPreferences.getString(SHARED_KEY_L_USERNAME, "未知姓名");
    }
    //存取员工NUM
    public void setLUserNum(String num) {
        editor.putString(SHARED_KEY_L_USERNUM, num);
        editor.commit();
    }

    public String getLUserNum() {
        return mSharedPreferences.getString(SHARED_KEY_L_USERNUM, "未知工号");
    }
    //存取员工ID
    public void setLUserId(String id) {
        editor.putString(SHARED_KEY_L_USERID, id);
        editor.commit();
    }

    public String getLUserId() {
        return mSharedPreferences.getString(SHARED_KEY_L_USERID, "未知ID");
    }

    /**
     * 清除所有存的共享参数
     */
    public void clearData(){
        editor.putString(SHARED_KEY_L_USERNAME, "未知姓名");
        editor.putString(SHARED_KEY_L_USERNUM, "未知工号");
        editor.putString(SHARED_KEY_L_USERNUM, "未知ID");
        editor.putString(SHARED_KEY_L_DOOR_TAKE_PROGRESS_TOTAL,"0");
        editor.putString(SHARED_KEY_L_DOOR_PUT_PROGRESS_TOTAL,"0");

        editor.putString(SHARED_KEY_L_HOSPITAL_CHECK_PROGRESS_TOTAL,"0");
        editor.putString(SHARED_KEY_L_HOSPITAL_TAKE_PROGRESS_TOTAL,"0");
        editor.putString(SHARED_KEY_L_HOSPITAL_PUT_PROGRESS_TOTAL,"0");

        editor.putString(SHARED_KEY_L_STATIC_CHECK_PROGRESS_TOTAL,"0");
        editor.putString(SHARED_KEY_L_STATIC_TAKE_PROGRESS_TOTAL,"0");
        editor.putString(SHARED_KEY_L_STATIC_PUT_PROGRESS_TOTAL,"0");
        editor.commit();
    }

    /**
     * 门诊药房 取药TAKE
     * @param size
     */
    public void setDoorMedicineProgressTotal(String size){
        editor.putString(SHARED_KEY_L_DOOR_TAKE_PROGRESS_TOTAL, size);
        editor.commit();
    }
    public String getDoorMedicineProgressTotal(){
        return mSharedPreferences.getString(SHARED_KEY_L_DOOR_TAKE_PROGRESS_TOTAL, "0");
    }
    /**
     * 门诊药房 上架
     * @param size
     */
    public void setDoorPutProgressTotal(String size){
        editor.putString(SHARED_KEY_L_DOOR_PUT_PROGRESS_TOTAL, size);
        editor.commit();
    }
    public String getDoorPutProgressTotal(){
        return mSharedPreferences.getString(SHARED_KEY_L_DOOR_PUT_PROGRESS_TOTAL, "0");
    }
    /**
     * 住院药房 CHECK
     * @param size
     */
    public void setHospitalCheckProgressTotal(String size){
        editor.putString(SHARED_KEY_L_HOSPITAL_CHECK_PROGRESS_TOTAL, size);
        editor.commit();
    }
    public String getHospitalCheckProgressTotal(){
        return mSharedPreferences.getString(SHARED_KEY_L_HOSPITAL_CHECK_PROGRESS_TOTAL, "0");
    }

    /**
     * 住院药房 TAKE
     * @param size
     */
    public void setHospitalTakeProgressTotal(String size){
        editor.putString(SHARED_KEY_L_HOSPITAL_TAKE_PROGRESS_TOTAL, size);
        editor.commit();
    }
    public String getHospitalTakeProgressTotal(){
        return mSharedPreferences.getString(SHARED_KEY_L_HOSPITAL_TAKE_PROGRESS_TOTAL, "0");
    }
    /**
     * 住院药房 上架 PUT
     * @param size
     */
    public void setHospitalPutProgressTotal(String size){
        editor.putString(SHARED_KEY_L_HOSPITAL_PUT_PROGRESS_TOTAL, size);
        editor.commit();
    }
    public String getHospitalPutProgressTotal(){
        return mSharedPreferences.getString(SHARED_KEY_L_HOSPITAL_PUT_PROGRESS_TOTAL, "0");
    }

    /**
     * 住院药房 包药 Pill
     * @param size
     */
    public void setHospitalPillProgressTotal(String size){
        editor.putString(SHARED_KEY_L_HOSPITAL_PILL_PROGRESS_TOTAL, size);
        editor.commit();
    }
    public String getHospitalPillProgressTotal(){
        return mSharedPreferences.getString(SHARED_KEY_L_HOSPITAL_PILL_PROGRESS_TOTAL, "0");
    }
    /**
     * 静配药房 CHECK
     * @param size
     */
    public void setStaticCheckProgressTotal(String size){
        editor.putString(SHARED_KEY_L_STATIC_CHECK_PROGRESS_TOTAL, size);
        editor.commit();
    }
    public String getStaticCheckProgressTotal(){
        return mSharedPreferences.getString(SHARED_KEY_L_STATIC_CHECK_PROGRESS_TOTAL, "0");
    }

    /**
     * 静配药房 TAKE
     * @param size
     */
    public void setStaticTakeProgressTotal(String size){
        editor.putString(SHARED_KEY_L_STATIC_TAKE_PROGRESS_TOTAL, size);
        editor.commit();
    }
    public String getStaticTakeProgressTotal(){
        return mSharedPreferences.getString(SHARED_KEY_L_STATIC_TAKE_PROGRESS_TOTAL, "0");
    }
    /**
     * 住院药房 上架 PUT
     * @param size
     */
    public void setStaticPutProgressTotal(String size){
        editor.putString(SHARED_KEY_L_STATIC_PUT_PROGRESS_TOTAL, size);
        editor.commit();
    }
    public String getStaticPutProgressTotal(){
        return mSharedPreferences.getString(SHARED_KEY_L_STATIC_PUT_PROGRESS_TOTAL, "0");
    }
}
